import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextField;
import javax.swing.JButton;


public class EIBezeroaGehitu extends JFrame {

	private JPanel contentPane;
	private JTextField nanSartu;
	private JTextField izenaSartu;
	private JTextField abizenaSartu;
	private JTextField telefonoaSartu;
	private JTextField helbideaSartu;
	private JButton gehitu;
	private JButton logout;
	private JButton atzera;

	public EIBezeroaGehitu() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 600);
		setVisible(true);
		elementuakHasieratu();
		botoiakHasieratu();
	}
	
	public void elementuakHasieratu(){
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblBezeroBerriaSartu = new JLabel("Bezero berria sartu:");
		lblBezeroBerriaSartu.setFont(new Font("Dialog", Font.BOLD, 14));
		lblBezeroBerriaSartu.setBounds(282, 41, 198, 15);
		contentPane.add(lblBezeroBerriaSartu);
		
		JLabel lblNan = new JLabel("Nan");
		lblNan.setBounds(157, 112, 70, 15);
		contentPane.add(lblNan);
		
		JLabel lblIzena = new JLabel("Izena:");
		lblIzena.setBounds(157, 163, 70, 15);
		contentPane.add(lblIzena);
		
		JLabel lblAbizena = new JLabel("Abizena:");
		lblAbizena.setBounds(157, 217, 70, 15);
		contentPane.add(lblAbizena);
		
		JLabel lblTelefonoa = new JLabel("Telefonoa:");
		lblTelefonoa.setBounds(157, 263, 90, 15);
		contentPane.add(lblTelefonoa);
		
		JLabel lblHelbidea = new JLabel("Helbidea:");
		lblHelbidea.setBounds(157, 305, 70, 15);
		contentPane.add(lblHelbidea);
		
		nanSartu = new JTextField();
		nanSartu.setBounds(270, 110, 272, 19);
		contentPane.add(nanSartu);
		nanSartu.setColumns(10);
		
		izenaSartu = new JTextField();
		izenaSartu.setBounds(270, 162, 272, 17);
		contentPane.add(izenaSartu);
		izenaSartu.setColumns(10);
		
		abizenaSartu= new JTextField();
		abizenaSartu.setBounds(270, 216, 272, 17);
		contentPane.add(abizenaSartu);
		abizenaSartu.setColumns(10);
		
		telefonoaSartu = new JTextField();
		telefonoaSartu.setBounds(270, 262, 272, 17);
		contentPane.add(telefonoaSartu);
		telefonoaSartu.setColumns(10);
		
		helbideaSartu = new JTextField();
		helbideaSartu.setBounds(270, 305, 272, 15);
		contentPane.add(helbideaSartu);
		helbideaSartu.setColumns(10);
		
		gehitu = new JButton("Gehitu");
		gehitu.setBounds(345, 424, 117, 25);
		contentPane.add(gehitu);
		
		logout = new JButton("Logout");
		logout.setBounds(796, 12, 84, 25);
		contentPane.add(logout);
		
		atzera = new JButton("Atzera");
		atzera.setBounds(790, 502, 90, 25);
		contentPane.add(atzera);
	}
	
	public void botoiakHasieratu(){
		gehitu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nan = nanSartu.getText();
				String izena = izenaSartu.getText();
				String abizena = abizenaSartu.getText();
				int telefonoa = Integer.parseInt(telefonoaSartu.getText());				
				String helbidea = helbideaSartu.getText();
				Bezeroa b = new Bezeroa(nan, izena, abizena, telefonoa, helbidea);
				BezeroKudeatzailea.getInstantzia().bezeroaGehitu(b);
			}
		});
		
		
		atzera.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//EIIdazkari frame = new EIIdazkari();
				EIBezeroKudeatzailea frame = new EIBezeroKudeatzailea();
				EIBezeroaGehitu.this.dispose();
			}
		});
		
		logout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				EILogin frame = new EILogin();
				EIBezeroaGehitu.this.dispose();
			}
		});
	}
}
